home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3107 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: cville-srv.wam.umd.edu!jsquires
  2. From: jsquires@wam.umd.edu (jeffrey d squires)
  3. Newsgroups: comp.lang.c
  4. Subject: using MALLOC() w/ 2-d arrays
  5. Date: 26 Jan 1996 05:09:22 GMT
  6. Organization: University of Maryland College Park
  7. Message-ID: <4e9nm2$nna@cville-srv.wam.umd.edu>
  8. NNTP-Posting-Host: rac3.wam.umd.edu
  9. X-Newsreader: TIN [version 1.2 PL0]
  10.  
  11. I have a function that takes as one of its arguments:
  12.  
  13. unsigned char image[MAX_Y][MAX_X}
  14.  
  15.  
  16. I have a number of images which is determined at run time,
  17. therefore I can't declare the size of image_array[][MAX_Y][MAX_X].
  18.  
  19. In other words, I want to be able to allocate space for as many
  20. of these images as I need at run time.  I've tried everything
  21. (except the correct way).
  22.  
  23. I think I need something of the form:
  24.  
  25. unsigned char * image_array[MAX_Y][MAX_X];
  26.  
  27. image_array = (unsigned char *) malloc(.....sizeof(unsigned char));
  28.  
  29.  
  30. I know that if I declare:
  31. unsigned char image_array[10][MAX_Y][MAX_X];
  32.  
  33. I can successfully send this to the function, but what
  34. if I don't know that I'll need ten?  Can anyone tell
  35. me the proper solution?  Thank you.
  36.  
  37.  
  38.